<template>
  <div class="coupon-detail">
    <h2>优惠券详情</h2>
    <p><span class="color-9 t-16">优惠券标题：</span>{{couponDetail.title}}</p>
    <p><span class="color-9 t-16">描述：</span>{{couponDetail.descs}}</p>
    <p><span class="color-9 t-16">创建时间：</span>{{couponDetail.createTime}}</p>
    <p><span class="color-9 t-16">活动开始时间：</span>{{couponDetail.startTime}}</p>
    <p><span class="color-9 t-16">活动结束时间：</span>{{couponDetail.endTime}}</p>
    <p><span class="color-9 t-16">使用类型：</span>{{couponDetail.useType | fomatType}}</p>
    <p><span class="color-9 t-16">用户限制领取数量：</span>{{couponDetail.userLimitCount}}</p>
    <p><span class="color-9 t-16">创建人：</span>{{couponDetail.creater}}</p>
    <p><span class="color-9 t-16">优惠券额度：</span>{{couponDetail.amount|fomatMoney}}</p>
    <p><span class="color-9 t-16">满多少使用：</span>{{couponDetail.amountLimit|fomatMoney}}</p>
    <div v-if="couponDetail.useType==2">
      <p><span class="color-9 t-16">绑定产品：</span>{{couponDetail.productName}}</p>
      <div class="flex">
        <span class="color-9 t-16">绑定商品：</span>
        <span v-for="(item,index) in couponDetail.goodsNameList"
              class="margin-right-10"
              :key="item.id"><span class="color-9 t-12">商品{{index+1}}:</span>{{item}}
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import { getCouponInfo } from '../../services/service_coupon'
export default {
  name: "coupon-detail",
  data () {
    return {
      id: '',
      couponDetail: {}
    }
  },
  methods: {
    async getDetail (id) {
      const res = await getCouponInfo(id)
      if (res.code == 0) {
        this.couponDetail = res.data
        console.log(this.couponDetail);
      } else {
        this.$message.warning(res.msg)
      }
    }
  },
  filters: {
    fomatMoney (moneyFen) {
      // console.log(moneyFen);
      return `${moneyFen / 100}元`
    },
    fomatType (type) {
      if (type == 1) {
        return '全商品'
      } else {
        return '部分商品'
      }
    }
  },
  created () {
    this.id = this.$route.query.id
    console.log(this.$route.query.id);

    this.getDetail(this.$route.query.id)
  }
}
</script>

<style lang="scss" scoped>
</style>